package com.jerkin.easyexcl;

import java.math.BigDecimal;

/**
 * @version V1.0
 * @ClassName: OilTypeEnum
 * @Description:
 * @author: huhongzhi
 * @date: 2020/9/21 16:31
 */
public enum OilTypeEnum {


    Oiml("ml","L",new BigDecimal("0.001")),
    OiML("ML","L",new BigDecimal("0.001")),
    OikL("L","L",new BigDecimal("1")),
    Oikl("l","L",new BigDecimal("1")),
    OilKG("KG","KG",new BigDecimal("1")),
    Oilkg("kg","KG",new BigDecimal("1")),
    OilKg("Kg","KG",new BigDecimal("1")),
    OilkG("kG","KG",new BigDecimal("1")),
    OilQT("QT","L",new BigDecimal("0.946") ),
    Oilqt("qt","L",new BigDecimal("0.946") ),
    OilG("G","KG",new BigDecimal("0.001") ),
    Oilg("g","KG",new BigDecimal("0.001") );
    private String type;

    private String unit;
    private BigDecimal amount;

    private OilTypeEnum(String type, String unit,BigDecimal  amount) {
        this.type = type;
        this.unit = unit;
        this.amount = amount;
    }

    public String  getType() {
        return type;
    }

    public BigDecimal getBigDecimal() {
        return amount;
    }

    public String getUnit() {
        return unit;
    }

    public static BigDecimal initAmount(String name ) {
        for(OilTypeEnum accStateEnum : OilTypeEnum.values()) {

            if(name .contains(accStateEnum.getType() )) {

                return accStateEnum.getBigDecimal().multiply(new BigDecimal(name.split(accStateEnum.getType())[0])) ;
            }
        }
        return null;
    }
//	accNum.contains("L")

    public static String initUnit(String name) {
        for(OilTypeEnum accStateEnum : OilTypeEnum.values()) {
            if(name .contains(accStateEnum.getType() )) {
                return accStateEnum.getUnit();
            }
        }
        return null;
    }

}
